package com.power.taskcenter.util;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.quartz.CronExpression;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;







public class BusinessUtils {




	public static String getNextDateTimeStr(String crontab, Date startDate)  {

		CronExpression cronExpression = null;
		try {
			cronExpression = new CronExpression(crontab);
		} catch (ParseException e) {
			return null;
		}
		Date d = cronExpression.getNextValidTimeAfter(startDate);
		if (ObjectUtil.isNotNull(d)){
			return  DateUtil.format(d ,"yyyy-MM-dd HH:mm:ss");
		}else{
			return null;
		}

	}
	public static void main(String[] args){

        System.out.println("0 0 0/1 * * ?   "+ getNextDateTimeStr("0 0 0/1 * * ?",new Date()));
		System.out.println("0/20 * * * * ?   "+ getNextDateTimeStr("0/20 * * * * ?",new Date()));
		System.out.println("0 0 23 * * ?   "+ getNextDateTimeStr("0 0 23 * * ?",new Date()));
		System.out.println("0 30 21 * * ?   "+ getNextDateTimeStr("0 30 21 * * ?",new Date()));
		System.out.println("0 0/15 * * * ?   "+ getNextDateTimeStr("0 0/15 * * * ?",new Date()));



	}


	
}
